<?php
	include("includes/connect.php");
	include("includes/function.php");

	$petition_id = $_REQUEST["petition_id"];
	//echo $petition_id;

	$db = new myDBS;

	$sql= "SELECT tbl_petition.*, expend_type, expend_sub_type, expend_mini_type FROM tbl_petition, expend,expend_mini, expend_sub WHERE petition_id  = '$petition_id' and expend.expend_id = dd_expend_type and expend_sub.expend_sub_id = dd_expend_sub_type and expend_mini.expend_mini_id= dd_expend_mini_type";
	//echo $sql;
	$result = $db->runSQL($sql);
	$rows = $db->fetch_object ( $result );

// just require TCPDF instead of FPDF

	//define('FPDF_FONTPATH','fpdf/font/');
	require_once('fpdf/TCPDF/tcpdf.php');
	require_once('fpdf/FPDI/fpdi.php');

	class PDF extends FPDI {
		/**
		 * "Remembers" the template id of the imported page
		 */
		var $_tplIdx;
		
		/**
		 * include a background template for every page
		 */
		function Header() {
			if (is_null($this->_tplIdx)) {
				$this->setSourceFile('pdf_form/petition1.pdf');
				$this->_tplIdx = $this->importPage(1);
			}
			$this->useTemplate($this->_tplIdx);
			
			/*
			//$this->AddFont('THSarabunNew','','THSarabunNew.php');
			//$this->SetFont('THSarabunNew', '', 9);
			$this->SetTextColor(255);
			$this->SetXY(60.5, 24.8);
			$this->Cell(0, 8.6, "TCPDF and FPDI");
			*/
		}
		
		function Footer() {}
	}

	// initiate PDF
	$pdf = new PDF();
	$pdf->SetMargins(PDF_MARGIN_LEFT, 40, PDF_MARGIN_RIGHT);
	$pdf->SetAutoPageBreak(true, 40);
	$pdf->setFontSubsetting(false);

	// add a page
	$pdf->AddPage();

	//$pdf->AddFont('THSarabunNew','','THSarabunNew.php');
	//$pdf->SetFont("freeserif", "", 12);
	$pdf->SetFont('thsarabunb','B',15);
	// now write some text above the imported page
	$pdf->SetXY(26, 27);
	$pdf->Write(0, $rows->gov);

	$pdf->SetXY(28, 34);
	$pdf->Write(0, $rows->dd_budget_year);

	$pdf->SetXY(21, 41);
	$pdf->Write(0, $rows->panngan2_name);

	$pdf->SetXY(81, 41);
	$pdf->Write(0, $rows->panngan3_name);

	$pdf->SetXY(25, 48);
	$pdf->Write(0, $rows->expend_type);

	$pdf->SetXY(87, 48);
	$pdf->Write(0, $rows->expend_sub_type);

	$pdf->SetXY(73, 69);
	$pdf->Cell(41,0,number_format($rows->inpValues, 2),0,0,'R');

	$pdf->SetXY(73, 76);
	$pdf->Cell(41,0,number_format($rows->inpTax, 2),0,0,'R');

	$pdf->SetXY(73, 83);
	$pdf->Cell(41,0,number_format($rows->inpTotal, 2),0,0,'R');

	$pdf->SetXY(73, 90);
	$pdf->Cell(41,0,number_format($rows->WithholdingTax, 2),0,0,'R');

	$pdf->SetXY(73, 97);
	$pdf->Cell(41,0,number_format($rows->inpPenalty, 2),0,0,'R');

	$pdf->SetXY(73, 111);
	$pdf->Cell(41,0,number_format($rows->inpNet, 2),0,0,'R');

	$pdf->SetXY(20, 171);
	$pdf->Cell(39,0,number_format($rows->inpNet, 2),0,0,'C');

	$pdf->SetXY(88, 171);
	$pdf->Cell(39,0,number_format($rows->inpNet, 2),0,0,'C');

	$pdf->SetXY(155, 171);
	$pdf->Cell(39,0,number_format($rows->inpNet, 2),0,0,'C');

	$pdf->SetXY(29, 226);
	$pdf->Cell(36,0,number_format($rows->inpNet, 2),0,0,'C');

	$pdf->SetXY(27, 233);
	$pdf->Write(0, $rows->company_name);

	$pdf->SetXY(35, 247);
	$pdf->Cell(55,0,number_format($rows->inpNet, 2),0,0,'C');



	$pdf->Output('output_petition1.pdf', 'I');
?>